package net.wanho.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import net.wanho.dto.LoginUserDTO;
import net.wanho.service.LoginService;
import net.wanho.util.SMSUtil;
import net.wanho.vo.AjaxResult;
import net.wanho.vo.CaptchaVo;
import net.wanho.vo.LoginVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * Author：汤小洋
 * Date：2025-09-25 11:13
 * Description：<描述>
 */
@Api(tags = "01.登录接口")
@RestController
@RequiredArgsConstructor
public class LoginController {

    private final LoginService loginService;

    @ApiOperation("用户登录")
    @PostMapping("/login")
    public AjaxResult login(@ApiParam("登录用户信息") @RequestBody LoginUserDTO loginUserDTO){
        LoginVo loginVo = loginService.login(loginUserDTO);
        return AjaxResult.success(loginVo);
    }

    @ApiOperation(("获取验证码"))
    @GetMapping("/captchaImage")
    public AjaxResult captchaImage(){
        CaptchaVo captchaVo = loginService.captcha();
        return AjaxResult.success(captchaVo);
    }

    @ApiOperation("带验证码的登录")
    @PostMapping("/captchaLogin")
    public AjaxResult captchaLogin(@ApiParam("登录用户信息") @RequestBody LoginUserDTO loginUserDTO){
        LoginVo loginVo = loginService.captchaLogin(loginUserDTO);
        return AjaxResult.success(loginVo);
    }

    @ApiOperation("退出")
    @PostMapping("/logout")
    public AjaxResult logout(){
        // todo...

        return AjaxResult.success();
    }

    @GetMapping("/smsCode")
    public AjaxResult smsCode(){

        SMSUtil smsUtil = new SMSUtil();
        smsUtil.sendMessage("13951783475","6666");

        return AjaxResult.success();
    }

}
